from django.contrib import admin
from booktest.models import BookInfo, HeroInfo
# 创建一个新的class类  作为一对多的多方关联文件

class HeroInfoTabularInline(admin.TabularInline):
    model = HeroInfo# 要编辑的对象是heroinfo  作为多方存在于bookinfo里
    extra = 1# 添加编辑的数量

# Register your models here.

# admin.site.register(BookInfo)
# admin.site.register(HeroInfo)
@admin.register(BookInfo)
class BookInfoAdmin(admin.ModelAdmin):
    list_per_page = 5

    actions_on_top = True
    actions_on_bottom = True
    # 注册列表中的列，
    list_display = ['id', 'btitle', 'pub_date', 'bread']

    # fields = ['btitle','bpub_date']
    # 设置高级and基本是因为有些数据不许随意修改
    fieldsets = (
        ('基本', {'fields': ['btitle', 'bpub_date','image']}),
        ('高级', {
            'fields': ['bread', 'bcomment'],
            'classes': ('collapse',)
        })
    )
    # inlines = [HeroInfoStackInline]
    inlines = [HeroInfoTabularInline]



@admin.register(HeroInfo)
class HeroInfoAdmin(admin.ModelAdmin):
    list_per_page = 5

    actions_on_top = True
    actions_on_bottom = True
    list_display = ['id', 'hname', 'hbook', 'read']
    list_filter = ['hbook', 'hgender']
    search_fields = ['hname']

admin.site.site_header = '传智书城'
admin.site.site_title = '青春加油fm'
admin.site.index_title = '欢迎使用青春mis'




